var isBalanced = function(root) {
    const depth=(root)=>{
        if(!root)return 0
        let left=depth(root.left)
        if(left===-1)return -1
        let right=depth(root.right)
        if(right===-1)return -1
        if(Math.abs(left-right)<=1){
            return Math.max(left,right)+1
        }else{
            return -1
        }
    }
return depth(root)!==-1
}